home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Code / Chapter09 / ChangeSegmentsPanel.java < prev    next >
Text File  |  2000-08-27  |  2KB  |  75 lines

  1.  
  2. package applets;
  3.  
  4. import shout3d.*;
  5. import shout3d.core.*;
  6. import shout3d.math.*;
  7.  
  8.  
  9. public class ChangeSegmentsPanel extends Shout3DPanel implements DeviceObserver {
  10.    
  11.    
  12.    TimeSensor timer;
  13.    ScalarInterpolator si;
  14.    float[] first = {0.0f, .19f};
  15.    float[] second = {.2f, 1.0f};
  16.    boolean firstseg = false;
  17.   
  18.  
  19.    public ChangeSegmentsPanel (Shout3DApplet applet){
  20.       super(applet);
  21.    }
  22.       
  23.    public void customInitialize() {
  24.       addDeviceObserver(this,"MouseInput", null);
  25.  
  26.  
  27.       timer = (TimeSensor) getNodeByName("timer");
  28.       si = (ScalarInterpolator) getNodeByName("si");
  29.       
  30.    }
  31.  
  32.  
  33.    protected void finalize()  { 
  34.       removeDeviceObserver(this,"MouseInput");
  35.  
  36.    }
  37.  
  38.    
  39.    
  40.    public boolean onDeviceInput(DeviceInput di, Object userData) {
  41.       MouseInput mi = (MouseInput) di;
  42.       switch (mi.which){
  43.  
  44.          case MouseInput.DOWN:
  45.          
  46.             if(firstseg) {
  47.             
  48.                timer.loop.setValue(false);
  49.                timer.stop();      
  50.                timer.cycleInterval.setValue(8.0);
  51.                si.keyValue.setValue(second);
  52.                timer.start();
  53.                timer.loop.setValue(true);               
  54.                firstseg = false;   
  55.                return true;
  56.             }
  57.             else {
  58.                timer.loop.setValue(false);
  59.                timer.stop();
  60.                timer.cycleInterval.setValue(2.0);
  61.                si.keyValue.setValue(first);            
  62.                timer.start();
  63.                timer.loop.setValue(true);   
  64.  
  65.                firstseg = true;   
  66.                return true;
  67.             }
  68.                         
  69.       }//end of switch
  70.       
  71.       return false;
  72.    }
  73.  
  74.  
  75. }//end of class